package days3.easy.title169;

/**
 * @Author fengzihao
 * @Date 2024-04-17 15:54
 */
class Solution {
    public int majorityElement(int[] nums) {
        int flag = nums[0];
        int count = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == flag)
                count++;
            else
                count--;
            if (count<=0){
                flag = nums[i];
                count++;
            }
        }
        return flag;
    }
}
